<?php

class reliquat {

    protected function old_initAutoload() {

        $modelLoader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => '',
                    'basePath' => APPLICATION_PATH));

        $this->_acl = new Cab_Acl_Acl();
        $this->_auth = Zend_Auth::getInstance();
        if (!$this->_auth->hasIdentity()) {
            $this->_auth->getStorage()->read()->role = 'guest';
        }

        $fc = Zend_Controller_Front::getInstance();
        $fc->registerPlugin(new Cab_Controller_Plugin_Acl($this->_acl, $this->_auth));

        return $modelLoader;
    }

    protected function old_initMetadataCache() {

        // First, set up the Cache
        $frontendOptions = array('automatic_serialization' => true);
        $backendOptions = array('cache_dir' => APPLICATION_PATH . '/../cache');
        $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
        //Zend_Debug::dump($cache);
        // Next, set the cache to be used with all table objects
        Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
        Zend_Registry::set('cache', $cache);
    }

    public function old_initDbCache() {
        // bootstrap DB
        $this->bootstrap('db');
        $dbAdapter = $this->getResource('db');

        // bootstrap cache
        $this->bootstrap('cache');

        $cache = $this->getResource('cachemanager');
        Zend_Debug::dump($cache);

        // set db metadata cache
        //Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
    }

//$view->headScript()->appendFile('http//autobahn.tablesorter.com/jquery.tablesorter.min.js');
    // exemple d'inclusion par ordre (offset)
    // mettre les scripts dans l'ordre
    // placer celui-ci à un offset particulier pour s'assurer
    // de le charger en deuxieme
    // ordre = 2
    // $view->headScript()->offsetSetFile(100, '/public/js/myfuncs.js');
    // utiliser les effets de scriptaculous (append utilise
    // l'index suivant, c-à-d. 101)
    // ordre = 3
    // $view->headScript()->appendFile('/public/js/scriptaculous.js');
    // mais dans tous les cas, le script de base prototype
    // doit être chargé en premier :
    // ordre = 1
    // $view->headScript()->prependFile('/public/js/prototype.js');
    //
        // Ajoutons le au ViewRenderer
    //$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
    //$viewRenderer->setView($view);
    // Initialisation d'un autoload pour une application sans module
    // pas necessaire pour l'instant
    protected function _initAutoload() {


        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => '',
                    'basePath' => APPLICATION_PATH));

        //$resourceLoader->addResourceType('actionhelper', 'controllers/helpers/', 'Action_Helper');
        //var_dump($resourceLoader->getResourceTypes());
    }

    protected function old_initZFDebug() {
// Setup autoloader with namespace
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('ZFDebug');

// Ensure the front controller is initialized
        $this->bootstrap('FrontController');

// Retrieve the front controller from the bootstrap registry
        $front = $this->getResource('FrontController');

// Only enable zfdebug if options have been specified for it
        if ($this->hasOption('zfdebug')) {
// Create ZFDebug instance
            $zfdebug = new ZFDebug_Controller_Plugin_Debug($this->getOption('zfdebug'));

// Register ZFDebug with the front controller
            $front->registerPlugin($zfdebug);
        }
// In application.ini do the following:
// 
// [development : production]
// zfdebug.plugins.Variables = null
// zfdebug.plugins.Time = null
// zfdebug.plugins.Memory = null
// ...
// Plugins that take objects as parameters like Database and Cache
// need to be registered manually:
// $zfdebug->registerPlugin(new ZFDebug_Controller_Plugin_Debug_Plugin_Database($db));
// Alternative configuration without application.ini
// $options = array(
//     'plugins' => array('variables', 'database', 
//                        'file' => array('basePath' => '/Library/WebServer/Documents/budget', 'myLibrary' => 'Scienta'),
//                        'memory', 'time', 'registry', 
//                        //'auth',
//                        //'cache' => array('backend' => $cache->getBackend()), 
//                        'exception')
// );
// $zfdebug = new ZFDebug_Controller_Plugin_Debug($options);
// Register ZFDebug with the front controller
// $front->registerPlugin($zfdebug);
    }

    protected function old_initActionHelpers() {
//Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '\controllers\helpers', 'Gl');
//hooks cause action helper to autorun: http://akrabat.com/zend-framework/hooks-in-action-helpers/
// Zend_Controller_Action_HelperBroker::addHelper(new Cab_Action_Helper_HelperAuth());
//Zend_Controller_Action_HelperBroker::addHelper(new Action_Helper_Auth());
//echo APPLICATION_PATH . '/controllers/helpers';
//var_dump(Zend_Controller_Action_HelperBroker::getExistingHelpers());
    }

    protected function _initResourceLoader() {
        $resourceLoader = $this->getResourceLoader();
        $resourceLoader->addResourceType('actionhelper', 'controllers/helpers', 'Action_Helper');
    }

    protected function old_initAcl() {

        $Config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/acl.ini', APPLICATION_ENV);
//$Config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
        $aclModel = new Cab_Acl_Acl($Config); //new Model_Acl($Config);
        Zend_Registry::set('aclModel', $aclModel);
    }

    protected function old_initBaseUrl() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        return $this->view->baseUrl();
    }

    protected function old_initJavascriptFiles() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
// echo "<h1>" . $view->baseUrl() . "</h1>";
        $view->headLink()->prependStylesheet($view->baseUrl() . '/css/twistter/bootstrap.css');
    }

}